<?php

require_once(OC_App::getAppPath('company') . "/lib/helper.php");
require_once(OC_App::getAppPath('company') . "/lib/subaccounts.php");

$LoginStats = PUtil::checkUserLogin(true);
if ($LoginStats !== true) {
   echo $LoginStats;
   exit();
}

OCP\JSON::callCheck();

if(!PFactory::isMasterUser()) {
   OC_JSON::error(array('data' => array( 'message' => '您无权访问该资源')));
   exit;
}

$jobid = JRequest::getInt("jobid", 0);
$uid = JRequest::getString("uid", "");

$model = new PCompanyModelSubAccounts();

if (!$model->unsetJobManager($jobid, $uid)) {
   OC_JSON::error(array('data' => array( 'message' => $model->getError() ? $model->getError() : '保存失败')));
   exit();
}

$adminUsers = PCompanyHelper::getJobAdminUser($jobid, 6);
OC_JSON::success(array('data' => array('adminUsers' => $adminUsers)));